package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.domain.SanPham;
import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_PostService;
import com.tt.fashionWebSite.service.Ad_ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ProductController {
    @Autowired
    private Ad_ProductService ad_productService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetProductComment", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<BinhLuanDto>> getProductComment(HttpServletRequest request) {
        return new JsonResponseDto<List<BinhLuanDto>>(ad_productService.getProductComment(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_GetAllProduct", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<SanPhamDto>> getAllProduct(HttpServletRequest request) {
        return new JsonResponseDto<List<SanPhamDto>>(ad_productService.getAllProduct(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductListInProduct", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucSanPhamDto>> getAllProductListInProduct(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucSanPhamDto>>(ad_productService.getAllProductListInProduct(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductCommon_add", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductCommon(HttpServletRequest request, @RequestBody SanPhamDto productDto) {
        return new JsonResponseDto<Integer>(ad_productService.adminProductCommon(productDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductCommentPage/{maBL}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageListProduct(HttpServletRequest request, @PathVariable String maBL, Map<String, Object> map) throws ParseException {
        map.put("maBL", maBL);
        return new ModelAndView("admin/ad-product-comment-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductComment", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<BinhLuanDto> getProductCommentInfoEdit(HttpServletRequest request, @RequestBody BinhLuanDto commentDto) {
        return new JsonResponseDto<BinhLuanDto>(ad_productService.getProductCommentInfoEdit(commentDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerProductCommentEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<BinhLuanDto> registerProductCommentEdit(HttpServletRequest request, @RequestBody BinhLuanDto commentDto) {
        return new JsonResponseDto<BinhLuanDto>(ad_productService.registerProductCommentEdit(commentDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/ad_AddProductDetailInCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> addProductDetail(HttpServletRequest request, @RequestBody ChiTietSanPhamDto productDetailDto) {
        return new JsonResponseDto<Integer>(ad_productService.addProductDetail(productDetailDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductCommonPage/{maSP}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toProductCommonPage(HttpServletRequest request, @PathVariable String maSP, Map<String, Object> map) throws ParseException {
        map.put("maSP", maSP);
        return new ModelAndView("admin/ad-product-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductDetailPage/{maSP}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toProductDetailPage(HttpServletRequest request, @PathVariable String maSP, Map<String, Object> map) throws ParseException {
        map.put("maSP", maSP);
        return new ModelAndView("admin/ad-product-detail-common");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductCommon", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<SanPhamDto> getProductInfoEdit(HttpServletRequest request, @RequestBody SanPhamDto productDto) {
        return new JsonResponseDto<SanPhamDto>(ad_productService.getProductInfoEdit(productDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerProductEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<SanPhamDto> registerProductEdit(HttpServletRequest request, @RequestBody SanPhamDto productDto) {
        return new JsonResponseDto<SanPhamDto>(ad_productService.registerProductEdit(productDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getProductWidthCategoryM/{maDMSP}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<SanPhamDto>> getProductWidthCategoryM(HttpServletRequest request, @PathVariable String maDMSP) throws ParseException {
        return new JsonResponseDto<List<SanPhamDto>>(ad_productService.getProductWidthCategoryM(maDMSP), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getProductWidthCategoryF/{maDMSP}", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<SanPhamDto>> getProductWidthCategoryF(HttpServletRequest request, @PathVariable String maDMSP) throws ParseException {
        return new JsonResponseDto<List<SanPhamDto>>(ad_productService.getProductWidthCategoryF(maDMSP), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/deleteProductCommon/", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> deleteProductCommon(HttpServletRequest request, @RequestBody SanPhamDto sanPhamDto) {
        return new JsonResponseDto<Integer>(ad_productService.deleteProductCommon(sanPhamDto));
    }
}
